<template>
<div class="student-container student-stories-wrap">
       <activity-deatil :detail="activityDeatil"></activity-deatil>
       <div class="fixed-tools-wrap">
          <div class="fixed-tools button-groups">
             <button class="btn btn-primary btn-sm" 
              @click="invitation()"
              >邀请卡</button>
            <button class="btn btn-primary btn-sm" 
              @click="showCart()"
              >{{stateMap[activityDeatil.state] || '立即报名'}}</button>
          </div>
       </div>
</div>

</template>

<script>
    import {OFFLINE_ACTIVITY_DETAIL,
OFFLINE_ACTIVITY_QRCODE} from '../../api';
    import activityDeatil from '../../components/activity';
    import jskit from '../../assets/jskit';
    export default {
        data(){
            return{
               activityDeatil:{},
               stateMap:{
                  1:'立即报名',
                  2:'已结束',
                  3:'已取消',
                  4:'已删除'
               }
            }
        },
        methods:{
            invitation(){
              this.$http.get(OFFLINE_ACTIVITY_QRCODE,{
                offlineactivity_id:this.$route.params.activityId
              })
              .then(res =>{
                  if(res.data.code ==0){
                    this.$toast.show('线下活动邀请卡生成成功');
                  }else{
                    this.$toast.show(res.data.message);
                  }
              })
            },
            showCart(){
              location.href = this.activityDeatil.apply_link;
            },
             getActivityDetail(){
              this.$http.get(OFFLINE_ACTIVITY_DETAIL,{
                offlineactivity_id:this.$route.params.activityId
              })
              .then(res =>{
                  if(res.data.code ==0){
                    this.activityDeatil = res.data.data;
                    jskit.openShare && jskit.openShare({
                      title:this.activityDeatil.title,
                      desc:this.activityDeatil.introduction.substring(0,100),
                      img:this.activityDeatil.cover_img[0]
                    })
                  }else{
                    this.$toast.show(res.data.message);
                  }
              })
             }
        },
        ready(){
          this.getActivityDetail();
        },
        components:{
          'activity-deatil':activityDeatil
        }
    }
</script>
<style lang="sass">
     @import "../../sass/detail.scss";
</style>
